#include "StomperLib/Controls/FileTree.h"
#include "StomperLib/Elements/FileSelection.h"

namespace StomperLib {
namespace Elements
{
FileSelection::FileSelection( StomperLib::BaseLayout* layout,
                              StompedReality::IGame* game ) : StomperLib::ToolElement( layout, game, NULL )
{
  CreateGui( layout );
}

FileSelection::~FileSelection( )
{
}

void FileSelection::Draw( ) {
}

bool FileSelection::Update( ) {
  return false;
}

void FileSelection::RefreshTree( )
{
  m_TextureTree->Refresh( );
}

void FileSelection::CreateGui( StomperLib::BaseLayout* layout )
{
  auto window = layout->CreateSubWindow( "Image Files", "Ctrl + Shift + i", true );
  m_TextureTree = new StomperLib::Controls::FileTree( (Gwen::Controls::WindowControl*) window );
  m_TextureTree->SetGame( this->m_Game );
  m_TextureTree->SetPath( "." );
  m_TextureTree->SetFilter( StompedReality::Utility::ImageFileFilter );
  m_TextureTree->onFileSelection.Add( this, &FileSelection::OnFileSelectionChange );
  m_TextureTree->onFileAdded.Add( this, &FileSelection::OnFileAdded );
  m_TextureTree->Dock( Gwen::Pos::Fill );
}

void FileSelection::OnFileSelectionChange( Gwen::Event::Info info )
{
  this->onFileChanged.Call( info.Control, info );
}

void FileSelection::OnFileAdded( Gwen::Event::Info info )
{
  this->onFileAdded.Call( info.Control, info );
}

void FileSelection::OnModified( Gwen::Event::Info info )
{
  this->m_TextureTree->NotifyNotSaved( info.String.Get( ));
}

void FileSelection::OnSaved( Gwen::Event::Info info )
{
  this->m_TextureTree->NotifySaved( info.String.Get( ));
}

}
}